/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package email;

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

/**
 *
 * @author Wizz
 */
public class Email {


        public Email(){

        }
        /**
         *
         * @param email
         * @param subjectOfMail
         * @param messageOfMail
         * @throws MessagingException
         */
        public static void sendMail(String email, String subjectOfMail, String messageOfMail) throws MessagingException
        {

            //Using the projects own gmail to send an email with the user information.
            String host = "smtp.gmail.com";
            String username = "amp.book";
            String password2 = "bookstore";

            //Building the message that is going to be sent.
            String subject = subjectOfMail;
            String message = messageOfMail;

            Properties props = new Properties();
            props.put("mail.smtps.auth", "true");

            Session session = Session.getInstance(props, null);

            MimeMessage msg = new MimeMessage(session);

            InternetAddress addressFrom = new InternetAddress(username);
            msg.setFrom(addressFrom);

            InternetAddress addressTo = new InternetAddress(email);
            msg.setRecipient(Message.RecipientType.TO, addressTo);
            msg.setSubject(subject);
            msg.setText(message);

            Transport t = session.getTransport("smtps");
            try {
                t.connect(host, username, password2);
                t.sendMessage(msg, msg.getAllRecipients());
            } finally {
               t.close();
            }

        }
}
